package GUI;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;

import org.jdesktop.application.Application;

import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class search extends javax.swing.JFrame {
	private JPanel zero;
	private JPanel bar;
	private JPanel text;
	private static JLabel searchPrice;
	private static JLabel searchCalorie;
	private static JLabel searchCarbon;
	private static JLabel searchg2;
	private static JLabel searchg1;
	private static JLabel searchkcal;
	private static JButton searchSubmit;
	private static JTextField searchFatField;
	private static JTextField searchProteinField;
	private static JTextField searchCarbonField;
	private static JTextField searchCalorieField;
	private static JTextField searchFoodField;
	private static JLabel searchFat;
	private static JLabel searchProtein;
	private static JLabel searchFoodName;
	private static JLabel Search;
	private JButton jButton4;
	private static JLabel Testing;
	private static JTextField searchPriceField;
	private static JLabel searchg3;
	private static JButton jButton1;
	private static JButton jButton3;
	private static JButton jButton2;
	private static JLabel jLabel1;
	private JPanel heading;
	
	private static String foodnamevar;
	private static String pricevar;
	private static String calorievar;
	private static String fatvar;
	private static String carbonvar;
	private static String proteinvar;
	

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				search inst = new search();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public search() {
		super();
		initGUI();
	}
	

    
	 class Action implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			MainPage frame = new MainPage();
			frame.setVisible(true);
			dispose();
			}}
	class Action2 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			myMenu frame = new myMenu();
			frame.setVisible(true);
			dispose();
			}}
	class Action3 implements ActionListener{    
		public void actionPerformed(ActionEvent e){

			}}
	
	
	 class searchSubmit implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			
			

			foodnamevar = searchFoodField.getText();
			pricevar = searchPriceField.getText();
			calorievar = searchCalorieField.getText();
			carbonvar = searchCarbonField.getText();
			fatvar = searchCarbonField.getText();
			proteinvar = searchProteinField.getText();
			String nth = "null";
			String sqlStmt = "SELECT * FROM food where price>=0 ";
			if(!"null".equals(foodnamevar))
			{
				sqlStmt=sqlStmt+" and name like '" +foodnamevar + "%' or name like '%" +foodnamevar + "%'";	
			}
			if(!"0".equals(pricevar))
				sqlStmt=sqlStmt+" and price<= "+pricevar;
			if(!"0".equals(calorievar))
				sqlStmt=sqlStmt+" and calories<= " + calorievar;
			if(!"0".equals(carbonvar))
				sqlStmt=sqlStmt+" and carbohydrate<= "+carbonvar;
			if(!"0".equals(proteinvar))
				sqlStmt=sqlStmt+" and protein<= " + proteinvar;
			if(!"0".equals(fatvar))
				sqlStmt=sqlStmt+" and fat<= "+fatvar;	
			
			String sqlfoodsearch = sqlStmt;
			System.out.println(sqlfoodsearch);
						Testing.setText("No Result" );	
						RM inst = new RM();
						inst.location(sqlfoodsearch,true);
						dispose();
						
			}}
    
	
	
	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			thisLayout.rowWeights = new double[] {0.0, 0.1};
			thisLayout.rowHeights = new int[] {52, 7};
			thisLayout.columnWeights = new double[] {0.0, 0.1};
			thisLayout.columnWidths = new int[] {118, 7};
			getContentPane().setLayout(thisLayout);
			{
				zero = new JPanel();
				getContentPane().add(zero, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				zero.setName("zero");
				{
					jButton4 = new JButton();
					zero.add(jButton4);
					jButton4.setName("jButton4");
					jButton4.setPreferredSize(new java.awt.Dimension(110, 50));
					try {
					    Image img = ImageIO.read(getClass().getResource("2.jpg"));
					    jButton4.setIcon(new ImageIcon(img));
					  } catch (IOException ex) {
						  
					  }
				}

			}
			{
				heading = new JPanel();
				getContentPane().add(heading, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				heading.setName("heading");
				{
					Search = new JLabel();
					heading.add(Search);
					Search.setName("Search");
					Search.setPreferredSize(new java.awt.Dimension(350, 44));
				}
			}
			{
				bar = new JPanel();
				GridBagLayout barLayout = new GridBagLayout();
				barLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				barLayout.rowHeights = new int[] {40, 40, 40, 40, 40, 40};
				barLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				barLayout.columnWidths = new int[] { 7};
				bar.setLayout(barLayout);
				getContentPane().add(bar, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				bar.setName("bar");
				{
					jButton1 = new JButton();
					bar.add(jButton1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					jButton1.setName("jButton1");
					jButton1.addActionListener(new Action());   
					jButton1.setText("Restaurant Menu");
				}
				{
					jButton2 = new JButton();
					bar.add(jButton2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					jButton2.setName("jButton2");
					jButton2.addActionListener(new Action2());   
					jButton2.setText("My Menu");
				}
				{
					jButton3 = new JButton();
					bar.add(jButton3, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					jButton3.setName("jButton3");
					jButton3.addActionListener(new Action3());   
					jButton3.setText("Search");
				}
			}
			{
				text = new JPanel();
				GridBagLayout textLayout = new GridBagLayout();
				textLayout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0};
				textLayout.rowHeights = new int[] {31, 30, 32, 30, 30, 30};
				textLayout.columnWeights = new double[] {0.0, 0.0, 0.1, 0.1};
				textLayout.columnWidths = new int[] {160, 130, 7, 7};
				text.setLayout(textLayout);
				getContentPane().add(text, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				text.setName("text");
				{
					jLabel1 = new JLabel();
					text.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
				}
				{
					searchFoodName = new JLabel();
					text.add(searchFoodName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchFoodName.setName("jLabel2");
					searchFoodName.setText("    Food Name (Keyword) :");
				}
				{
					searchPrice = new JLabel();
					text.add(searchPrice, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchPrice.setName("jLabel3");
					searchPrice.setText("    Price :$                            <=");
				}
				{
					searchCalorie = new JLabel();
					text.add(searchCalorie, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchCalorie.setName("jLabel4");
					searchCalorie.setText("    Calorie                             <=");
				}
				{
					searchCarbon = new JLabel();
					text.add(searchCarbon, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchCarbon.setName("jLabel5");
					searchCarbon.setText("    Carbonhydrate :            <=");
				}
				{
					searchProtein = new JLabel();
					text.add(searchProtein, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchProtein.setName("jLabel6");
					searchProtein.setText("    Protein :                           <=");
				}
				{
					searchFat = new JLabel();
					text.add(searchFat, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchFat.setName("jLabel7");
					searchFat.setText("    Fat:                                   <=");
				}
				{
					searchFoodField = new JTextField();
					text.add(searchFoodField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchFoodField.setName("jTextField2");
					this.foodnamevar = searchFoodField.getText();
				}
				{
					searchCalorieField = new JTextField();
					text.add(searchCalorieField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchCalorieField.setName("jTextField4");
					this.calorievar = searchCalorieField.getText();
				}
				{
					searchCarbonField = new JTextField();
					text.add(searchCarbonField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchCarbonField.setName("jTextField5");
					this.carbonvar = searchCarbonField.getText();
				}
				{
					searchProteinField = new JTextField();
					text.add(searchProteinField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchProteinField.setName("jTextField6");
					this.proteinvar = searchProteinField.getText();
				}
				{
					searchFatField = new JTextField();
					text.add(searchFatField, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchFatField.setName("jTextField7");
					this.fatvar = searchFatField.getText();;
				}
				{
					searchSubmit = new JButton();
					text.add(searchSubmit, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					searchSubmit.setName("jButton4");
					searchSubmit.setText("Submit");
					searchSubmit.addActionListener(new searchSubmit());  
				}
				{
					searchkcal = new JLabel();
					text.add(searchkcal, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					searchkcal.setName("jLabel8");
				}
				{
					searchg1 = new JLabel();
					text.add(searchg1, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					searchg1.setName("jLabel9");
				}
				{
					searchg2 = new JLabel();
					text.add(searchg2, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					searchg2.setName("jLabel10");
				}
				{
					searchg3 = new JLabel();
					text.add(searchg3, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					searchg3.setName("jLabel11");
				}
				{
					searchPriceField = new JTextField();
					text.add(searchPriceField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					searchPriceField.setName("jTextField3");
					this.pricevar = searchPriceField.getText();
				}
				{
					Testing = new JLabel();
					text.add(Testing, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					Testing.setName("Testing");
					//Testing.setText("Output Test");

				}
			}
			pack();
			this.setSize(650, 600);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
